<template>
	<view class="content">
		<view class="catList">
			<catLabel dataType="text" text="姓名"  v-model="realName"/>
			<catLabel dataType="text" inputType="number" text="手机"  v-model="phone"/>
			<catLabel dataType="text" text="职位"  v-model="position"/>
			<!-- <catLabel text='所属行业' @handSelect="selectIndustry" :initIndex="industryIndex" dataType="selector" :selectList="industryArr" /> -->
			<catLabel dataType="text" text="邮箱"  v-model="email"/>
			<catLabel dataType="text" text="公司"  v-model="companyName"/>
			<catLabel text="公司地址" :dataText="addressTotal" dataType="region"  @handRegion ="selectAddress" />
			<catLabel dataType="text" text="详细地址"  v-model="addressDetail"/>
		</view>
		<button class="submit" @click="completeData">提交</button>
	</view>
</template>

<script>
	import { mapState, mapGetters, mapMutations, mapActions } from 'vuex'
	import catLabel from "@/components/cat-label/cat-label.vue"
	export default {
		data() {
			return {
				realName:'',
				phone:'',
				position:'',
				email:'',
				
				companyName:'',
				companyProvince:'',
				companyCity:'',
				companyArea:'',
				
				addressDetail:'',
				industryIndex:0,
				industryArr:[{label:'text1',value:1,index:0},{label:'text2',value:99,index:1}],
				addressTotal:'选择地址'//显示用的地址
			}
		},
		
		components:{
			catLabel
		},
		onLoad() {
			this.getUserInfo()
		},
		methods: {
			...mapActions('userInfo', [
			      'setUserInfoAsync' // 将 `this.increment()` 映射为 `this.$store.dispatch('increment')`
			    ]),
			async getUserInfo(){
				let userToken=uni.getStorageSync('userToken');
				if(userToken){
					let res=await this.$api.getUserInfo({
						user_token:userToken
					})
					if(res.data.level=='success'){
						let data=res.data.data;
						this.setUserInfoAsync(data);
						this.realName=data.realname;
						this.phone=data.phone_number;
						this.position=data.position;
						this.email=data.email;
						this.companyName=data.company;
						this.companyProvince=data.company_province?data.company_province:'';
						this.companyCity=data.company_city?data.company_city:'';
						this.companyArea=data.company_area?data.company_area:'';
						this.addressDetail=data.company_address?data.company_address:'';
						this.addressTotal=this.companyProvince+this.companyCity+this.companyArea;
						console.log(this.companyProvince,this.companyCity,this.companyArea)
					}
				}
				
			},
			selectIndustry(val){
				//所属行业val
				this.industryIndex = val.checkArr.index;
			},
			selectAddress(val){
				//公司地址
				console.log(val)
				this.addressTotal=val.result;
				let checkArr=val.checkArr;
				this.companyProvince=checkArr[0];
				this.companyCity=checkArr[1];
				this.companyArea=checkArr[2];
			},
			async completeData(){
				//完善资料
				let userToken=uni.getStorageSync('userToken');
				let parmas={
					real_name:this.realName,
					phone_number:this.phone,
					position:this.position,
					email:this.email,
					company:this.companyName,
					company_province:this.companyProvince,
					company_city:this.companyCity,
					company_area:this.companyArea,
					company_address:this.addressDetail,
					user_token:userToken
				}
				
				let res=await this.$api.completeData(parmas);
				uni.showToast({
					icon:'none',
					title:res.data.message
				})
				if(res.data.level=='success'){
					this.getUserInfo();//更新数据
					setTimeout(()=>{
						uni.switchTab({
							url:'/pages/me/index'
						})
					},2000)
				}
			}
		}
	}
</script>

<style>
	.content {

	}
	.catList{
		padding-bottom:100rpx;
	}
	.submit{
		position: fixed;
		bottom:0rpx;
		width: 100%;
		background: linear-gradient(-135deg, #57D1E2 0%, #37AED6 100%);
		color:#fff
	}
</style>
